package com.gjy.scheduling.monitor.log;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.sift.AbstractDiscriminator;

import java.util.Map;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-07-11 15:32:14
 */
public class RoutingKeyDiscriminator extends AbstractDiscriminator<ILoggingEvent> {

    @Override
    public String getDiscriminatingValue(ILoggingEvent event) {
        Map<String, String> mdcMap = event.getMDCPropertyMap();
        if (mdcMap == null) {
            return "";
        }
        String mdcValue = mdcMap.get("ROUTING_KEY");
        if (mdcValue == null) {
            return "";
        } else {
            return "_" + mdcValue;
        }
    }

    @Override
    public String getKey() {
        return "ROUTING_KEY";
    }

}
